#include "Vector.h"

//Default constructor
Vector3::Vector3()
{
	x = y = z = 0.0f;
}

//Initialization
Vector3::Vector3(float a, float b, float c)
{
	x = a;
	y = b;
	z = c;
}

//Operators
//Common functions

//Get a negated vector
Vector3 Vector3::operator - ()
{
	return Vector3(-x, -y, -z);
}

//Add two vectors
Vector3 Vector3::operator + (const Vector3& V2)
{
	return Vector3(x+V2.x, y+V2.y, z+V2.z);
}

//Subtract two vectors
Vector3 Vector3::operator - (const Vector3& V2)
{
	return Vector3(x-V2.x, y-V2.y, z-V2.z);
}

//Multiply by a scalar
Vector3 Vector3::operator * (float k)
{
	return Vector3(k*x, k*y, k*z);
}

//Divide by a scalar
Vector3 Vector3::operator / (float k)
{
	float inv = 1/k;
	return Vector3(x*inv, y*inv, z*inv);
}

//Dot product
float Vector3::operator * (const Vector3& V2)
{
	return (x*V2.x + y*V2.y + z*V2.z);
}

//Cross product
Vector3 Vector3::operator ^ (const Vector3& V2)
{
	return Vector3(y*V2.z - z*V2.y,
				    z*V2.x - x*V2.z,
					x*V2.y - y*V2.x);
}

//Length
float Vector3::Length()
{
	return sqrtf(x*x + y*y + z*z);
}

//Abs Length
//Returns squared length
float Vector3::AbsLength()
{
	return (x*x + y*y + z*z);
}

//Normalize vector
void Vector3::Normalize()
{
	float inv_length = 1/sqrtf(x*x + y*y + z*z);
	x *= inv_length;
	y *= inv_length;
	z *= inv_length;
}

//Get Normalized Vector3
Vector3 Vector3::GetNormalizedVector() const
{
	float inv_length = 1/sqrtf(x*x + y*y + z*z);
	return Vector3(x*inv_length, y*inv_length, z*inv_length);
}



	




